package com.rabbitmq.routing;

import com.rabbitmq.client.*;
import com.rabbitmq.utils.RabbitMqUtils;

import java.io.IOException;

/**
 * @author lipengwei
 */
public class Customer02 {

    public static void main(String[] args) throws IOException {
        Connection connection = RabbitMqUtils.getConnection();
        Channel channel = connection.createChannel();
        channel.exchangeDeclare("logs_direct", "direct");
        // 创建一个队列
        String queue = channel.queueDeclare().getQueue();
        // 基于route key 绑定队列和交换机
        channel.queueBind(queue, "logs_direct", "info");
        channel.queueBind(queue, "logs_direct", "waring");
        channel.queueBind(queue, "logs_direct", "error");
        // 获取消费的消息
        channel.basicConsume(queue, true, new DefaultConsumer(channel) {
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("消费者1： " + new String(body));
            }
        });

    }

}
